package com.yegs.jindie.quartz;

import com.yegs.jindie.JindieApplication;
import com.yegs.jindie.entity.InventoryTO;
import com.yegs.jindie.service.InventoryService;
import com.yegs.jindie.util.ExcelUtil;
import com.yegs.jindie.util.TxtUtil;
import org.quartz.DisallowConcurrentExecution;

import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@DisallowConcurrentExecution
public class InventoryJob extends BaseJob{

    private InventoryService inventoryService = (InventoryService) JindieApplication.applicationContext.getBean("inventoryService");

    public String handle(Date beginDate, Date endDate, Integer int_last){
        try {
            beginDate = new SimpleDateFormat("yyyy-MM-dd").parse("2010-11-16");
            String fileName = inventoryService.getFileName(endDate, int_last);
            List<InventoryTO> list = inventoryService.getInventory(beginDate, endDate);
            ExcelUtil.exporExcelByFtp(fileName, InventoryTO.class, list);
            String path = TxtUtil.exporInventoryTOTxt(fileName,list);
            FileInputStream fi = new FileInputStream(path);
            //super.upload(fi,path);
            return "执行成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

}
